package de.htwds.mada.todolistDB.model;

import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "todo")
public class Todo implements Parcelable {

	public static final String TODO_ID_FIELD = "_id";
	public static final String TITLE_FIELD = "title";
	public static final String DESC_FIELD = "desc";
	public static final String DATE_FIELD = "date";
	public static final String PRIO_FIELD = "priority_id";

	@DatabaseField(columnName = TODO_ID_FIELD, generatedId = true)
	private int _id;

	@DatabaseField(columnName = TITLE_FIELD)
	private String title;

	@DatabaseField(columnName = DESC_FIELD)
	private String desc;

	@DatabaseField(columnName = DATE_FIELD)
	private Date date;

	@DatabaseField(columnName = PRIO_FIELD, foreign = true, foreignAutoRefresh = true)
	private Priority prio;

	public Todo() {
	}

	public Todo(String title, String desc, Date date, Priority prio) {
		this.title = title;
		this.desc = desc;
		this.date = date;
		this.prio = prio;
	}

	public int getId() {
		return _id;
	}

	public String getTitle() {
		return title;
	}

	public String getDesc() {
		return desc;
	}

	public Date getDate() {
		return date;
	}

	public Priority getPrio() {
		return prio;
	}

	public void setId(int id) {
		this._id = id;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setPrio(Priority prio) {
		this.prio = prio;
	}

	public String toString() {
		return title;
	}

	public String toStringComplete() {
		return "ToDoId: " + _id + ", Title: " + title + ", Desc: " + desc
				+ ", Date: " + date + ", Prio: " + prio;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(_id);
		dest.writeString(title);
		dest.writeString(desc);
		dest.writeSerializable(date);
		dest.writeSerializable(prio);

	}

	public static final Parcelable.Creator<Todo> CREATOR = new Parcelable.Creator<Todo>() {

		@Override
		public Todo createFromParcel(Parcel source) {
			return new Todo(source);
		}

		@Override
		public Todo[] newArray(int size) {
			return new Todo[size];
		}
	};

	public Todo(Parcel source) {
		this._id = source.readInt();
		this.title = source.readString();
		this.desc = source.readString();
		this.date = (Date) source.readSerializable();
		this.prio = (Priority) source.readSerializable();
	}

}
